package rsschart.init;

import java.io.FileInputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import rsschart.charter.CharterFactory;

public class InitServlet extends HttpServlet {

	@Override
	public void init() throws ServletException {
		
		ServletContext context = getServletContext();
		String configPath = context.getRealPath("/") + context.getInitParameter("configPath");
		FileInputStream inputStream;
		String inputFile=null;
		
		Properties charterProps = new Properties();
		
		try {
			inputFile =  configPath + "/charters.properties";
			inputStream = new FileInputStream(inputFile);
		}
		catch(Exception e) {
			throw new ServletException("Charter properties file not found: " + inputFile);
		}
		try {
			charterProps.load(inputStream);
			CharterFactory.load(charterProps);
		}
		catch(Exception e) {
			throw new ServletException("Exception loading charter config file: " + inputFile);
		}
        
		
	}
	
	 

}
